package org.his.service.impl;

import org.his.entity.Patient;
import org.his.entity.Prescription;
import org.his.entity.Registration;
import org.his.mapper.PrescriptionMapper;
import org.his.service.PrescriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PrescriptionServiceImpl implements PrescriptionService{
	@Autowired
	private PrescriptionMapper prescriptionMapper;

	public Prescription setPrescription(Registration registrationinfo, Patient patientinfo) {
		Prescription addPrescription =new Prescription();
		addPrescription.setDiagnosticcard(patientinfo.getDiagnosticcard());
		addPrescription.setSex(patientinfo.getSex());
		addPrescription.setMedicalrecord(registrationinfo.getMedicalrecord());

		addPrescription.setPatientname(registrationinfo.getPatientname());
		addPrescription.setAge(patientinfo.getAge());
		addPrescription.setPhone(patientinfo.getPhone());
		addPrescription.setDepartment(registrationinfo.getDepartment());
		addPrescription.setPastmedicalhistory(patientinfo.getPastmedicalhistory());
		return addPrescription;
	}

	public int addPresciption(Prescription addPrescription) {
		int count = 0;
		try {
			count = prescriptionMapper.addPresciption(addPrescription);
		} catch (Exception e) {
			e.printStackTrace();
			count = -1;
		}
		return count;
	}

	public Prescription queryByMedicalrecord(String selectMedicalrecord) {
		Prescription selectPrescription = prescriptionMapper.queryByMedicalrecord(selectMedicalrecord);
		return selectPrescription;
	}
}
